<extend name="Base/common"/>

<block name="style">
<link href="__CSS__/stylesheet.css" rel="stylesheet">
<link href="__CSS__/business.css" rel="stylesheet">
</block>

<block name="header">
<header>
	<include file="User/header" />
</header>
</block>

<block name="body">
<div class="container main">
	<div class="user-main">
		<div class="col-xs-3">
			<include file="Business/left_menu" />
		</div>
		<div class="col-xs-9">
			<h5>发布商品</h5>
			<div class="content">
				<form action="" method="post" class="form-horizontal" enctype="multipart/form-data">
					<div class="form-group">
						<label class="label-control">邀请码：</label>
						<div class="input-control">
							<input type="text" name="verify"  value="{$info.verify}"  placeholder="邀请码" class="form-control">
						</div>
					</div>
					<div class="form-group">
						<label class="label-control">商品标题：</label>
						<div class="input-control">
							<input type="text" name="title" value="{$info.title}"   placeholder="商品名称" class="form-control">
						</div>
					</div>
					<div class="form-group">
						<label class="label-control">商品分类：</label>
						<div class="input-control">
							<select name="category_id" class="form-control">
								<option value="">请选择分类</option>
								<<volist name=":getCategoryTree()" id="cate">
				     				<optgroup label="{$cate.title}">
				     					<volist name="cate._child" id="_child">
				     						<option value="{$_child.id}" <eq name="info.category_id" value="$_child.id">selected</eq>>{$_child.title}</option>
				     					</volist>
				     				</optgroup>
				     			</volist>
							</select>
						</div>
					</div>
					<div class="form-group">
						<label class="label-control">商品描述：</label>
						<div class="input-control">
							<textarea rows="6" class="form-control" name="description">{$info.description}</textarea>
							{:hook('adminArticleEdit', array('name'=>'description','value'=>$info['description']))}
						</div>
					</div>
					<div class="form-group">
						<label class="label-control">鉴定（包鉴定）：</label>
						<div class="input-control">
							<p><em class="price">{:isset($identify_price) ? $identify_price :'0'}</em>元</p>
						</div>
					</div>
					<div class="form-group">
						<label class="label-control">上传定制完成图样或视频：</label>
						<div class="input-control">
							<div class="files-btn" >
								<input type="file" id="file_img" class="upload-btn">
								<input type="file" id="file_video" class="upload-btn">
							</div>
							<div class="files">
								<volist name="pics" id="pic">
			     				<p class='file-info'>
			     				<img src="__ROOT__{$pic.cover_id|get_cover='path'}" />
			     				<input type="hidden" name="image_cover_id[]" value="{$pic.cover_id|default=''}"/>
			     				<a class='fr' href='javascript:;'><i class='icon-remove icon-large' ></i></a>
			     				</p>
				     			</volist>
							</div>
						</div>
					</div>					
					<div class="form-group">
						<label class="label-control">设置价格：</label>
						<div class="input-control col-xs-5">
							<div class="input-group">
								<input type="text" name="price" value="{$info.price}" placeholder="设置价格" class="form-control">
								<div class="input-group-addon">元</div>
							</div>
						</div>
					</div>
					<div class="form-group">
						<label class="label-control">交货期限：</label>
						<div class="input-control col-xs-5">
							<div class="input-group">
								<input type="text" name="end_time" value="{$info.end_time|time_format=###,'Y-m-d'}" placeholder="交货期限" class="form-control">
								<div class="input-group-addon">天</div>
							</div>
						</div>
					</div>
					<div class="form-group">
						<label class="label-control">每延期周期：</label>
						<div class="input-control col-xs-5">
							<div class="input-group">
								<input type="text" name="over_day" value="{$info.over_day}" placeholder="每延期周期" class="form-control">
								<div class="input-group-addon">天</div>
							</div>
						</div>
					</div>
					<div class="form-group">
						<label class="label-control">补偿百分比：</label>
						<div class="input-control col-xs-5">
							<div class="input-group">
								<input type="text" name="over_persent" value="{$info.over_persent}" placeholder="补偿百分比" class="form-control">
								<div class="input-group-addon">%</div>
							</div>
						</div>
					</div>
					<div class="form-group">
						<label class="label-control">发货地：</label>
						<div class="input-control">
							<select class="form-control input-select" name="province_id" id="province">
								<option>省份</option>
								<volist name=":getProvinces()" id="vo">
				    				<option value="{$vo.province_id}" <eq name="info.province_id" value="$vo.province_id">selected</eq>>{$vo.province}</option>
				    			</volist>
							</select>
							<script type="text/javascript">
				     		$(function(){
				     			$('#province').change(function(e){
				     				$('#city').html('<option value="">城市</option>');
				     				$('#area').html('<option value="">区县</option>');
				     				
				     				paramter = {format : 'json', province_id : $(this).val()};
				     				
				     				$.post('{:U('Api/Public/getCities')}', paramter, function(data){
				     					if (data.code == 1) {
				     						$.each(data.data, function(i, item){
				     							$('#city').append('<option value="' + item.city_id + '">' + item.city + '</option>');
				     						});
				     					}
				     				}, 'json');
				     			});
				     		});
				     		</script>
							<select class="form-control input-select" name="city_id" id="city">
								<notempty name="info.province_id">
				     				<volist name=":getCities($info['province_id'])" id="vo">
					      				<option value="{$vo.city_id}" <eq name="info.city_id" value="$vo.city_id">selected</eq>>{$vo.city}</option>
					      			</volist>
				     			</notempty>
							</select>
							<script type="text/javascript">
				     		$(function(){
				     			$('#city').change(function(e){
				     				$('#area').html('');			     				
				     				paramter = {format : 'json', city_id : $(this).val()};
				     				
				     				$.post('{:U('Api/Public/getAreas')}', paramter, function(data){
				     					$('#area').append('<option value="">区县</option>');
				     					if (data.code == 1) {
				     						$.each(data.data, function(i, item){
				     							$('#area').append('<option value="' + item.area_id + '">' + item.area + '</option>');
				     						});
				     					}
				     				}, 'json');
				     			});
				     		});
				     		</script>
							<select class="form-control input-select" name="area_id" id="area">
								<volist name=":getAreas($info['city_id'])" id="vo">
					      				<option value="{$vo.area_id}" <eq name="info.area_id" value="$vo.area_id">selected</eq>>{$vo.area}</option>
				      			</volist>					
							</select>
						</div>
					</div>
					<div class="form-group center" style="margin-top: 50px !important;">
						<label class="label-control"></label>
						<div class="input-control">
							<input type="hidden" name="type" value="dingzhi" />
							<input type="hidden" name="id" value="{$info.id}" />
							<a class="btn putinbtn" href="{:U('Business/addSuccess')}" target-form="form-horizontal">放入仓库</a>
							<a class="btn ajax-post" url="{:U('addProduct')}" target-form="form-horizontal">立即发布</a>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
</div>
</block>

<block name="script">
<script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>					
<script type="text/javascript">
//上传图片
   /* 初始化上传插件 */
$("#file_img").uploadify({
	"auto"          : true,
	"height"          : 30,
	"swf"             : "__STATIC__/uploadify/uploadify.swf",
	"fileObjName"     : "download",
	"buttonText"	  : "上传图片文件",
	"uploader"        : "{:U('File/uploadPicture',array('session_id'=>session_id()))}",
	"width"           : 120,
	'removeTimeout'	  : 0,
	'fileTypeExts'	  : '*.jpg; *.png; *.gif;',
	"onUploadSuccess" : uploadPicture_panel,
	'onFallback' : function() {
		alert('未检测到兼容版本的Flash.');
	}
   });
function uploadPicture_panel(file, data){
   	var data = $.parseJSON(data);							    	
       if(data.status){
    	   src = data.url || '__ROOT__' + data.path;
          	$(".files").append(
          			"<p class='file-info'>"
          			+"<img src="+src+" />"
          			+"<input type='hidden' name='image_cover_id[]' value="+data.info.id+" />"
          			+"<a class='fr' href='javascript:;'><i class='icon-remove icon-large'></i></a></p>" );  
       } else {
       	updateAlert(data.info);
       	setTimeout(function(){
               $('#top-alert').find('button').click();
               $(that).removeClass('disabled').prop('disabled',false);
           },1500);
       }
   }

   /* 初始化上传插件 */
$("#file_video").uploadify({
       "height"          : 30,
       "swf"             : "__STATIC__/uploadify/uploadify.swf",
       "fileObjName"     : "download",
       "buttonText"      : "上传视频文件",
       "uploader"        : "{:U('File/uploadMovie',array('session_id'=>session_id()))}",
       "width"           : 120,
       'removeTimeout'	  : 1,
       'multi'			  : false,
       'fileTypeExts'	  : '*.flv; *.avi; *.wma; *.rmvb; *.rm; *.flash; *.mp4; *.mid; *.3gp;',
       "onUploadSuccess" : uploadMovie,
       'onFallback' : function() {
           alert('未检测到兼容版本的Flash.');
       }
   });

function uploadMovie(file, data){
   	var data = $.parseJSON(data);
       if(data.status){    	   
    	   $(".files").append(
          			"<p class='file-info'>文件名称：<span class='file-name'>"
          			+file.name
          			+"</span>"
          			+"<input type='hidden' name='movie_id' value="+data.info.id+" />"
          			+"<a class='fr' href='javascript:;'><i class='icon-remove icon-large'></i></a></p>"
          	);      	
       } else {
       	alert(data.info);
       	setTimeout(function(){
               $('#top-alert').find('button').click();
               $(that).removeClass('disabled').prop('disabled',false);
           },1500);
       }
   }	

$("div").delegate(".icon-remove","click",function(){
	$(this).closest('p').remove();			
});
</script>	
<script type="text/javascript">	
$(function(){
	$("select[name='category_id']").change(function(){
		$.get('{:U('ajaxgetIdentify')}',{category_id:$(this).val()},function(data){
			$("em.price").text(data);
		});			
	});	

	highlight_leftnav("{:U('Business/addDingzhi')}");
	highlight_subnav("{:U('Business/index')}");
});
</script>
</block>